/*
 *  main.c
 *
 *  Created by Per-Anders Enarsson, DSY07
 *  Limited Copyright 2008. All rights reserved.
 *  Open source. Mailware. Might still be available at google code, search for xxxx
 *  You're allowed to use the code. And if you find it useful, send a mail to pason_67@yahoo.se
 *
 * Revision 0.1 20080929
 *
  */

#include <stdio.h>
#include <stdlib.h>
#include "esim.h"
#include "support.h"
#include "iniparser.h"

#define VERBOSE 1
#define NO_VERBOSE 0

/*
 **********************************************************
 * Globals
 **********************************************************
 */



/*
 **********************************************************
 * Prototyper
 **********************************************************
 */
dictionary openIniFile();

/*
 **********************************************************
 * Open ini file
 **********************************************************
 */
dictionary openIniFile(){
   static char * iniName="esim.ini";
   int success;
   dictionary * dict;
   dict =  iniparser_load(iniName);
   success=iniparser_getint(dict, "conf:days", -1);
   return *dict;
}

/*
 **********************************************************
 * Hämtar in vilket menyval som önskas
 **********************************************************
 */

int getChoise(int low, int high)
{
   int i=-1;                                                //Sätt i till ogiltigt
   while(1==1)                                              //Snurra tills break
   {
      printf("\nChoose menu item: \n"); scanf("%i", &i); 
      skipGarb();
      
      if(i>=low&&i<=high)                                        //Förväntar mig 0 til 7
         return i;                                          //Returnera resultat
      else{
         printf("\nInvalid input, select from %d to %d \n",low,high); printf("Press enter to continue"); getchar();
      }
   }
}


/*
 **********************************************************
 * Skriver ut menyn på skärmen
 **********************************************************
 */

int showMenu()
{
   clearScreen();
	
   printf("****************************************\n");
   printf("**    Main menu E-sim                 **\n");
   printf("**                                    **\n");
   printf("**        0 Quit                      **\n");
   printf("**        1 Run simulation            **\n");
   printf("**        2 Show result               **\n");
   printf("**        3 Edit configuration        **\n");
	printf("**                                    **\n");
    printf("****************************************\n");
   return 0;
}


/*
 **********************************************************
 * Main
 **********************************************************
 */

int main(int argc, char *argv[])
{
   makeConf();
   int choise=0;
   while (1==1) 
   {
      showMenu();                                           //Visa menyn
      choise = getChoise(0,3);                                 //Hämta val
      
      switch(choise)
      {
         case 0: return 0;   break;                         //Avsluta, fast breaken behövs egentligen inte
         case 1: simulate(); break;
         case 2: result();break;
         case 3: openIniFile(); changeConfig(); break;
         case 4: break;
         case 5: break;
         case 6:break;
         default: break;
      }
   }
      return 0;
}